package org.example.basic.day05;

import java.util.spi.LocaleNameProvider;

public class Demo03异常练习 {
    public static void main(String[] args) {
            Login login = new Login();
            try {
                login.login("","q");

            }catch (LoginNullException e){
                e.printStackTrace();
                System.out.println(e.getMessage());
            }catch (LoginExitException e){
                e.printStackTrace();
                System.out.println(e.getMessage());
            }catch (Exception e){
                e.printStackTrace();
                System.out.println(e.getMessage());
            }
    }
}

class Login{
    public void login(String username,String password) throws LoginNullException{
        if(username==null||username.trim().isEmpty()){
            //todo 用户名抛出异常
            throw new LoginNullException("用户名不能为空");
        }
        if(password==null||password.trim().isEmpty()){
            //todo 密码抛出异常
            throw new LoginNullException("密码不能为空");
        }
    }
}
/*
* 登录异常类
* */
class LoginException extends RuntimeException{
    public LoginException(String message){
        super(message);
    }
    public LoginException(){
        super();
    }
}

/*
* 用户名或密码不为空异常
* */
class LoginNullException extends LoginException{
    public LoginNullException(String message){
        super(message);
    }
    public LoginNullException(){
        super();
    }
}
/*
* 用户不存在异常
* */
class LoginExitException extends LoginException{
    public LoginExitException(String message){
        super(message);
    }
    public LoginExitException(){
        super();
    }
}
